using System.Threading.Tasks;

using Microsoft.AspNetCore.Identity;

using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Identity;
using Volo.Abp.Uow;

namespace ProjectTaskManager.IdentityServer
{
    public class UsersDataSeedContributor : IDataSeedContributor, ITransientDependency
    {
        private readonly IdentityUserManager _identityUserManager;
        private readonly IIdentityUserRepository _identityUserRepository;
        private readonly ILookupNormalizer _lookupNormalizer;

        public UsersDataSeedContributor(IdentityUserManager identityUserManager, IIdentityUserRepository identityUserRepository, ILookupNormalizer lookupNormalizer)
        {
            _identityUserManager = identityUserManager;
            _identityUserRepository = identityUserRepository;
            _lookupNormalizer = lookupNormalizer;
        }

        [UnitOfWork]
        public virtual async Task SeedAsync(DataSeedContext context)
        {
            var user = await _identityUserRepository.FindByNormalizedUserNameAsync(_lookupNormalizer.NormalizeName("admin"));
            await _identityUserManager.ChangePasswordAsync(user, "1q2w3E*", "1");
        }
    }
}
